var productDialog = null;

function setupMaplightCanvas(solutionSchemeCanvas) {
    solutionSchemeCanvas.parent().css({
        'width':'755px',
        'background-repeat':'no-repeat',
        'background-size':'cover'
    });
}

$(function () {
    if ($('#solution-page').length == 0) {
        return;
    }

    $('map[name=solution_scheme_map] area').bind('click', function (event) {
        if (productDialog != null) productDialog.dialog('close');
        productDialog = $('div[name="product_dialog"][productId="' + $(this).attr('productId') + '"]').dialog({
            autoOpen:false,
            modal:true,
            width:800,
            height:600
        });
        if (productDialog) {
            productDialog.dialog('option', 'title', productDialog.attr('productName'));
            productDialog.dialog('open');
            $('button.ui-dialog-titlebar-close').attr('title', 'Закрыть');
        }
    });

    var solutionSchemeCanvas = $('img#solution_scheme_canvas');
    solutionSchemeCanvas.css({
        'maxWidth':'755px',
        'opacity':'1'
    });
    solutionSchemeCanvas.maphilight();

    setupMaplightCanvas(solutionSchemeCanvas);
    setTimeout(function(){
        setupMaplightCanvas(solutionSchemeCanvas);
    }, 1000);
});